package _binary_search;

/**
 * 69. x 的平方根
 */
public class No69 {
    public int mySqrt(int x) {
        int left = 1, right = Math.min(x, 1 << 16);
        while (left <= right) {
            int mid = left + (right - left) / 2;
            long cur = (long) mid * mid;
            if (cur <= x) left = mid + 1;
            else right = mid - 1;
        }
        return left - 1;
    }
}
